<?php
function dossier_ecrire($dossier)
 {
    if($dossier == '') return false;
    else
    {
        if (is_dir($dossier)) @chmod ($dossier, 0777); else return false;
		if (!is_writable($dossier)) return false; else return true;
    }
 }
 
 function get_currentpage()
{
	$path = $_SERVER['PHP_SELF'];
	$file = basename ($path);
	return $file;
}
 
function blok_etape_installation()
{
global $lang;
$page = get_currentpage();
$color[3] = '#0871bb';
$color[2] = '#58b6f8';
$blok='';
$blok .= '<fieldset>
<table style="width: 100%;">
	<tr><td style="background: '. $color[3] .'; text-align: center;"><strong>'. $lang['LISTE_ETAPES'] .'</strong></td></tr>';
    switch($page)
    {
        case 'index.php':
            $blok .= '<tr><td style="background: #FFFFFF; color:#000;">'. $lang['DEBUT_INSTALLATION'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['VERIFICATION_SYSTEME'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_DB'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CREATION_COMPTE_ADMIN'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_SITE'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['FIN_INSTALLATION'] .'</td></tr>';
            break;
            
        case 'page_check_system.php':
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['DEBUT_INSTALLATION'] .'</td></tr>';
            $blok .= '<tr><td style="background: #FFFFFF; color:#000;">'. $lang['VERIFICATION_SYSTEME'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_DB'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CREATION_COMPTE_ADMIN'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_SITE'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['FIN_INSTALLATION'] .'</td></tr>';
            break;
        
         case 'page_config_database.php':
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['DEBUT_INSTALLATION'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['VERIFICATION_SYSTEME'] .'</td></tr>';
            $blok .= '<tr><td style="background: #FFFFFF; color:#000;">'. $lang['CONFIGURATION_DB'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CREATION_COMPTE_ADMIN'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_SITE'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['FIN_INSTALLATION'] .'</td></tr>';
            break;
        
        case 'page_compte_admin.php':
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['DEBUT_INSTALLATION'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['VERIFICATION_SYSTEME'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_DB'] .'</td></tr>';
            $blok .= '<tr><td style="background: #FFFFFF; color:#000;">'. $lang['CREATION_COMPTE_ADMIN'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_SITE'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['FIN_INSTALLATION'] .'</td></tr>';
            break;
            
        case 'page_config_site.php':
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['DEBUT_INSTALLATION'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['VERIFICATION_SYSTEME'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_DB'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CREATION_COMPTE_ADMIN'] .'</td></tr>';
            $blok .= '<tr><td style="background: #FFFFFF; color:#000;">'. $lang['CONFIGURATION_SITE'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['FIN_INSTALLATION'] .'</td></tr>';
            break;
        
        case 'page_fin_installation.php':
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['DEBUT_INSTALLATION'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['VERIFICATION_SYSTEME'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_DB'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CREATION_COMPTE_ADMIN'] .'</td></tr>';
            $blok .= '<tr><td style="background: '. $color[2] .';">'. $lang['CONFIGURATION_SITE'] .'</td></tr>';
            $blok .= '<tr><td style="background: #FFFFFF; color:#000;">'. $lang['FIN_INSTALLATION'] .'</td></tr>';
            break;
        
    }

$blok .= '
</table></fieldset>';
return $blok;
}
/**
*Ecrit le fichier de config
*/  
function write_config_file($basesql, $_POST)
{
$siteurl = "http://" . $_SERVER['SERVER_NAME'] . str_replace("install/page_config_database.php", "", $_SERVER['SCRIPT_NAME']);
if (substr($siteurl, -1) == "/") $siteurl = substr($siteurl, 0, -1); 
$content ='<?php
$basesql = array(
\'serveur\'	=>	\''. $basesql['serveur'] .'\',
\'user\'	=>	\''. $basesql['user'] .'\',
\'password\'	=>	\''. $basesql['password'] .'\',
\'base\'	=>	\''. $basesql['base'] .'\',
\'type\'	=>	\''.$_POST['typebase'].'\',
);
$config = array(
\'url\'	=>	\''. $siteurl  .'/\');
?>';
$patch = '../conf/config.php';
@chmod($path, 0777); 
$fp = @fopen($patch, "w+");
fwrite($fp, $content);
fclose($fp);
@chmod($path, 0444);

// WRITE main.file.php
	
}
/**
*	redirect
*/
function redirect($url, $tps = 0)
{
    $temps = $tps * 1000;
    echo "<script type=\"text/javascript\">\n"
    . "<!--\n"
    . "\n"
    . "function redirect() {\n"
    . "window.location='" . $url . "'\n"
    . "}\n"
    . "setTimeout('redirect()','" . $temps ."');\n"
    . "\n"
    . "// -->\n"
    . "</script>\n";
    exit;
}
?>